package com.gy.algorithm.carl.hashtableexa;

import java.util.HashSet;
import java.util.Set;

/**
 * @BelongsProject: javabase
 * @BelongsPackage: com.gy.algorithm.carl
 * @Author: gy
 * @Date: 2024/10/22 11:30
 * @Description:
 */
public class Intersection349 {

    public static void main(String[] args) {

    }

    // end
//    public static boolean isAnagram(String s, String t) {
//
//    }

    // write
    public static int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> tmp = new HashSet<>();
        Set<Integer> resSet = new HashSet<>();

        for (int i = 0; i < nums1.length; i++) {
            tmp.add(nums1[i]);
        }

        for (int i = 0; i < nums2.length; i++) {
            if(tmp.contains(nums2[i])) resSet.add(nums2[i]);
        }

        int[] res = new int[resSet.size()];
        int j = 0;
        for (Integer i : resSet) {
            res[j++] = i;
        }

        return res;
    }
}
